<?php
declare (strict_types=1);

namespace app\admin\service\finance;

use app\admin\logic\finance\Encashment as EncashmentLogic;
use app\common\service\BaseService;
use eduline\admin\libs\pagelist\ListItem;
use eduline\admin\page\PageList;
use think\annotation\Inject;
use think\facade\Request;

/**
 * 提现管理
 */
class Encashment extends BaseService
{
    /**
     * @Inject()
     *
     * @var EncashmentLogic
     */
    protected $encashmentLogic;

    /**
     * 提现列表
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date：   2020-06-23
     */
    function list(string $type)
    {
        $data = $this->encashmentLogic->getList($type);

        // 定义字段
        $keyList = [
            'user_name'   => ListItem::make()->title('用户'),
            'money'       => ListItem::make('custom')->title('提现金额'),
            'type'        => ListItem::make('custom')->title('提现方式'),
            'status'      => ListItem::make('custom')->title('提现状态'),
            'update_time' => ListItem::make()->title('最后更新时间'),
        ];

        // 设置表单
        $list = app(PageList::class);
        // 表单字段
        $list->pageKey = $keyList;
        // $list->searchKey = $searchKey;
        $list->datas = $data;

        return $list->send();
    }

    /**
     * 提现审核
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date：   2020-06-24
     */
    public function editEncashment($order_no)
    {
        if (Request::isPut()) {
            $param = Request::put();
            $data  = $this->encashmentLogic->where('order_no', $order_no)->findOrFail();
            $this->encashmentLogic->editEncashment($data, $param);
            return $this->parseToData([], 1, '处理成功');
        }

        $data = $this->encashmentLogic->with(['user_name'])->where('order_no', $order_no)->findOrFail();

        return $this->parseToData($data, 1);
    }
}
